package com.example.demo.user.controller;

import com.example.demo.user.entity.User;
import com.example.demo.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@RestController
@Api(tags = "user")
@EnableSwagger2
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "添加用户")
    @PostMapping("/addUser")
    public int addUser(User user) {
        return userService.insertUser(user);
    }
    @ApiOperation(value = "删除用户")
    @PostMapping("/deleteUSer")
    public int deleteUSer (int id) {
        return userService.deleteUser(id);
    }
    @ApiOperation(value = "更新用户")
    @PostMapping("/updateUser")
    public int updateUser(User user) {
        return userService.updateUser(user);
    }
    @ApiOperation(value = "查询所有用户")
    @GetMapping("/selectAll")
    public List<User> selectAll(){
        return userService.selectAllUser();
    }
}
